package com.sense.kukoo.biz_me.vm

import androidx.lifecycle.MutableLiveData
import com.sense.kukoo.common.mvvm.model.BaseMvvmModel
import com.sense.kukoo.common.mvvm.vm.BaseViewModel

class PhoneNumberViewModel:BaseViewModel() {

    private val TAG: String = javaClass.simpleName

    val action_toVerifyCode:MutableLiveData<Boolean> = MutableLiveData()
    val action_toSelectCountry:MutableLiveData<Boolean> = MutableLiveData()

    val mAreaCode:MutableLiveData<String> = MutableLiveData("66")
    val mPhoneNumber:MutableLiveData<String> = MutableLiveData("")
    val mIsShowPhoneErrorHit:MutableLiveData<Boolean> = MutableLiveData(false)
    val mBtnEnable:MutableLiveData<Boolean> = MutableLiveData(false)

    override fun createModel(): BaseMvvmModel? = null

    override fun initData() {}

    fun onAreaClick(){
        action_toSelectCountry.postValue(true)
    }

    fun onEnterClick(){
        val phone = mPhoneNumber.value ?: ""
        //todo 手机号码校验
        /*if(phone.length != 11){
            mIsShowPhoneErrorHit.postValue(true)
        }else{
            action_toVerifyCode.postValue(true)
        }*/
        if(phone.length <= 0){
            mIsShowPhoneErrorHit.postValue(true)
        }else{
            action_toVerifyCode.postValue(true)
        }
    }

    fun onEditChanged(){
        //todo 手机号码校验
        /*if(mPhoneNumber.value?.length == 11){
            mBtnEnable.postValue(true)
        }else{
            mBtnEnable.postValue(false)
        }*/
        val len = mPhoneNumber.value?.length ?: 0
        if(len > 0){
            mBtnEnable.postValue(true)
        }else{
            mBtnEnable.postValue(false)
        }
        mIsShowPhoneErrorHit.postValue(false)
    }
}